/*
  ==============================================================================

   This file is part of the JUCE library - "Jules' Utility Class Extensions"
   Copyright 2004-11 by Raw Material Software Ltd.

  ------------------------------------------------------------------------------

   JUCE can be redistributed and/or modified under the terms of the GNU General
   Public License (Version 2), as published by the Free Software Foundation.
   A copy of the license is included in the JUCE distribution, or can be found
   online at www.gnu.org/licenses.

   JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
   A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

  ------------------------------------------------------------------------------

   To release a closed-source product which uses JUCE, commercial licenses are
   available: visit www.rawmaterialsoftware.com/juce for more information.

  ==============================================================================
*/

#if JUCE_USE_D3D9_SHADERS

D3D9ShaderProgram::D3D9ShaderProgram (const D3D9Context& context_) noexcept
    : context (context_)
{
    // This object can only be created and used when the current thread has an active OpenGL context.
    jassert (D3D9Helpers::isContextActive());

    //programID = context.extensions.glCreateProgram();
}

D3D9ShaderProgram::~D3D9ShaderProgram() noexcept
{
    //context.extensions.glDeleteProgram (programID);
}

double D3D9ShaderProgram::getLanguageVersion()
{

    //return String ((const char*) glGetString (GL_SHADING_LANGUAGE_VERSION))
    //        .upToFirstOccurrenceOf (" ", false, false).getDoubleValue();
	return 0.0f;
}

bool D3D9ShaderProgram::addShader (const char* const code, DWORD type)
{
    //GLuint shaderID = context.extensions.glCreateShader (type);
    //context.extensions.glShaderSource (shaderID, 1, (const GLchar**) &code, nullptr);
    //context.extensions.glCompileShader (shaderID);

    //GLint status = GL_FALSE;
    //context.extensions.glGetShaderiv (shaderID, GL_COMPILE_STATUS, &status);

    //if (status == GL_FALSE)
    //{
    //    GLchar infoLog [16384];
    //    GLsizei infologLength = 0;
    //    context.extensions.glGetShaderInfoLog (shaderID, sizeof (infoLog), &infologLength, infoLog);
    //    errorLog = String (infoLog, infologLength);

    //   #if JUCE_DEBUG
    //    DBG (errorLog);
    //    jassertfalse;
    //   #endif

    //    return false;
    //}

    //context.extensions.glAttachShader (programID, shaderID);
    //context.extensions.glDeleteShader (shaderID);
    //JUCE_CHECK_OPENGL_ERROR
    return true;
}

bool D3D9ShaderProgram::link() noexcept
{
    //context.extensions.glLinkProgram (programID);

    //GLint status = GL_FALSE;
    //context.extensions.glGetProgramiv (programID, GL_LINK_STATUS, &status);

    //if (status == GL_FALSE)
    //{
    //    GLchar infoLog [16384];
    //    GLsizei infologLength = 0;
    //    context.extensions.glGetProgramInfoLog (programID, sizeof (infoLog), &infologLength, infoLog);
    //    errorLog = String (infoLog, infologLength);

    //   #if JUCE_DEBUG
    //    DBG (errorLog);
    //    jassertfalse;
    //   #endif
    //}

    //JUCE_CHECK_OPENGL_ERROR
    //return status != GL_FALSE;
	return true;
}

void D3D9ShaderProgram::use() const noexcept
{
    //context.extensions.glUseProgram (programID);
}

//D3D9ShaderProgram::Uniform::Uniform (const D3D9ShaderProgram& program, const char* const name)
//    : uniformID (program.context.extensions.glGetUniformLocation (program.programID, name)), context (program.context)
//{
//    jassert (uniformID >= 0);
//}
//
//D3D9ShaderProgram::Attribute::Attribute (const OpenGLShaderProgram& program, const char* name)
//    : attributeID (program.context.extensions.glGetAttribLocation (program.programID, name))
//{
//    jassert (attributeID >= 0);
//}

//void D3D9ShaderProgram::Uniform::set (float n1) const noexcept                                    { context.extensions.glUniform1f (uniformID, n1); }
//void D3D9ShaderProgram::Uniform::set (int n1) const noexcept                                      { context.extensions.glUniform1i (uniformID, n1); }
//void D3D9ShaderProgram::Uniform::set (float n1, float n2) const noexcept                        { context.extensions.glUniform2f (uniformID, n1, n2); }
//void D3D9ShaderProgram::Uniform::set (float n1, float n2, float n3) const noexcept            { context.extensions.glUniform3f (uniformID, n1, n2, n3); }
//void D3D9ShaderProgram::Uniform::set (float n1, float n2, float n3, float n4) const noexcept  { context.extensions.glUniform4f (uniformID, n1, n2, n3, n4); }
//void D3D9ShaderProgram::Uniform::set (int n1, int n2, int n3, int n4) const noexcept        { context.extensions.glUniform4i (uniformID, n1, n2, n3, n4); }
//void D3D9ShaderProgram::Uniform::set (const float* values, GLsizei numValues) const noexcept      { context.extensions.glUniform1fv (uniformID, numValues, values); }

#endif
